<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0" />
    <title>dc-example</title>
    <script src="/libs/dc-sdk/dc.min.js"></script>
    <link href="/libs/dc-sdk/dc.min.css" type="text/css" rel="stylesheet" />
    <link href="../index.css" type="text/css" rel="stylesheet" />
  </head>

  <body>
    <div id="viewer-container" class="viewer-container"></div>
    <script>
      DC.config.baseUrl = '../libs/dc-sdk/resources/'
      let viewer = new DC.Viewer('viewer-container')
      let baseLayer = DC.ImageryLayerFactory.createImageryLayer(
        DC.ImageryType.AMAP,
        {
          style: 'img',
          crs: 'WGS84',
        }
      )
      viewer.addBaseLayer(baseLayer, {
        brightness: 0.1,
      })
      let layer = new DC.TilesetLayer('layer')
      viewer.addLayer(layer)
      let build = new DC.Tileset(
        'http://resource.dvgis.cn/data/3dtiles/ljz/tileset.json',
        { skipLevels: true }
      )
      let customShader = new DC.CustomShader({
        fragmentShaderText: `
      void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) {
         vec4 position = czm_inverseModelView * vec4(fsInput.attributes.positionEC,1); // 位置
         float glowRange = 100.0; // 光环的移动范围(高度)
         vec4 temp = vec4(0.2,  0.5, 1.0, 1.0); // 颜色
         temp *= vec4(vec3(position.z / 100.0), 1.0);  // 渐变
         // 动态光环
         float time = fract(czm_frameNumber / 360.0);
         time = abs(time - 0.5) * 2.0;
         float diff = step(0.005, abs( clamp(position.z / glowRange, 0.0, 1.0) - time));
         material.diffuse = vec3(temp.rgb + temp.rgb * (1.0 - diff)) ;
       }
      `,
      })
      build.setCustomShader(customShader)
      layer.addOverlay(build)
      viewer.flyTo(build)
    </script>
  </body>
</html>
